package model;

import java.io.Serializable;

import jade.core.AID;

public class Step implements Serializable {
	private static final long serialVersionUID = 1L;
	// this should contain the information about the plan that the agv should
	// execute, i.e., where the agv should move the product
	// the plan should contain: the source (mac agent), destination (mac agent),
	// product (including weight and volume)
	// should have a tostring, or be serializable
	AID sourceID;
	AID destinationID;
	Position source;
	Position destination;
	Product product;

	public Step(AID sourceID, AID destinationID, Position source,
			Position destination, Product product) {
		this.sourceID = sourceID;
		this.destinationID = destinationID;
		this.source = source;
		this.destination = destination;
		this.product = product;
	}

	public float getTotalDistance(Position p) {

		if(destination == null)
		{
			System.out.println("something went terrebly wrong!");
		}
		
		if(source != null)
		{
			float distanceToSource = source.findDistance(p);
			float distanceFromSourceToDestination = destination
					.findDistance(source);
			float totalDistance = distanceToSource
					+ distanceFromSourceToDestination;

			return totalDistance;
		}else{
			//agv already went to source
			float distanceToDestination = destination.findDistance(p);
			return distanceToDestination;
		}

	}

	public Product getProduct() {
		return product;
	}

	public Position getSource() {
		return source;
	}

	public Position getDestination() {
		return destination;
	}

	public void pickupPerformed() {
		this.source = null;
	}

	public AID getSourceID() {
		return sourceID;
	}

	public AID getDestinationID() {
		return destinationID;
	}
	
	@Override
	public String toString() {
		if(sourceID != null){
			return sourceID.getLocalName() + "," + destinationID.getLocalName();
		}
		else{
			return "" + destinationID.getLocalName();
		}
	}
}
